import os
from os.path import join, getsize

def get_dir_size(dir):
    size = 0
    for root, dirs, files in os.walk(dir):
        size += sum([getsize(join(root, name)) for name in files])
    return size


if __name__ == '__main__':
    file_size = get_dir_size('C:\Users\14531\Desktop\作业')
    print(' you have %.3f' % (file_size / 1024 / 1024 ), r'M  in  your C:\Users\14531\Desktop\作业')

